@import 'pdfjs-dist/web/pdf_viewer.css';

:root {
  /* Modern color palette */
  --body-bg-color: #f5f5f7;
  --main-color: #2c2c2e;
  --accent-color: #aabb11;
  --accent-hover: #aabb11;
  --toolbar-height: 32px;
  --toolbar-bg-color: rgba(255, 255, 255, 1);
  --toolbar-border-color: rgba(0, 0, 0, 0.1);
  --field-color: #2c2c2e;
  --field-height: 24px;
  --field-bg-color: rgba(240, 240, 245, 1);
  --field-border-color: rgba(210, 210, 215, 1);
  --hover-bg-color: rgba(235, 235, 240, 1);
  --sidebar-width: 250px;

  /* Transitions */
  --transition-speed: 0.2s;

  /* Shadows */
  --toolbar-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --button-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

html {
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  html {
    color-scheme: dark light;
  }
  
  :root {
    --body-bg-color: #1e1e1e;
    --main-color: #f5f5f7;
    --toolbar-bg-color: rgba(42, 42, 42, 1);
    --field-color: var(--dark-main-color);
    --field-bg-color: rgba(60, 60, 65, 1);
    --field-border-color: rgba(80, 80, 85, 1);
    --hover-bg-color: rgba(75, 75, 80, 1);
    --button-bg-color: rgba(50, 50, 50, 0.8);
  }
}

* {
  padding: 0;
  margin: 0;
}

html, body {
  height: 100%;
  width: 100%;
}
body {
  background-color: var(--body-bg-color);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

.hidden, [hidden] {
  display: none !important;
}

#outerContainer {
  width: 100%;
  height: 100%;
  position: relative;
  margin: 0;
}
#mainContainer {
  position: absolute;
  inset: 0;
  min-width: 350px;
  margin: 0;
  display: flex;
  flex-direction: column;
}
#viewerContainer {
  overflow: auto;
  position: absolute;
  inset: var(--toolbar-height) 0 0;
  outline: none;
  z-index: 0;
  transition: inset-inline-start var(--transition-speed) ease;
}


#toolbarContainer {
  width: 100%;
  height: var(--toolbar-height);
  background-color: var(--toolbar-bg-color);
  box-shadow: var(--toolbar-shadow);
  border-bottom: none;
  backdrop-filter: blur(10px);
}
#toolbarViewer {
  height: var(--toolbar-height);
  display: flex;
  flex-direction: row;
  padding: 0 0.5rem;
  align-items: center;
}
#toolbarViewerMiddle {
  width: max-content;
  height: var(--toolbar-height);
  margin-left: auto;
  margin-right: auto;
  display: flex;
  align-items: center;
  gap: 0.2rem;
}
#toolbarViewerLeft, #toolbarViewerRight {
  display: flex;
  align-items: center;
}

.toolbar {
  position: relative;
  left: 0;
  right: 0;
  z-index: 9999;
  
  & input,
  & button,
  & select {
    outline: none;
    font-family: inherit;
    transition: all var(--transition-speed) ease;
  }
}



.toolbarField {
  margin: 0 0.2em;
  padding: 0 0.4rem;
  border-radius: 6px;
  background-color: var(--field-bg-color);
  background-clip: padding-box;
  border: 1px solid var(--field-border-color);
  box-shadow: var(--button-shadow);
  color: var(--field-color);
  font-size: 0.8rem;
  line-height: 1.4;
  height: var(--field-height);
  box-sizing: border-box;
  vertical-align: middle;
  display: inline-block;

  &:hover, &:focus-visible {
    background-color: var(--field-bg-color);
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(0, 113, 227, 0.2);
  }
}

.toolbarLabel {
  min-width: 1em;
  color: var(--main-color);
  text-align: left;
  user-select: none;
  cursor: default;
  font-size: 0.8rem;
  font-weight: 500;
}



#pageNumber {
  text-align: right;
  width: 3em;
  appearance: textfield;
  font-size: 0.8rem;
  font-weight: 500;

  &::-webkit-outer-spin-button, &::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }
}


#scaleSelect {
  cursor: pointer;
  padding-right: 1.5rem;
  
  & > option {
    color: var(--field-color);
    background-color: var(--field-bg-color);
  }
}


.toolbarButton {
  border: none;
  background: none;
  width: 1.8em;
  height: 1.8em;
  border-radius: 6px;
  color: var(--main-color);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-speed) ease;

  & svg {
    fill: var(--main-color);
    width: 1.5em;
    height: 1.5em;
    transition: transform var(--transition-speed) ease;
  }

  &[disabled] {
    opacity: 0.5;
  }

  &:hover, &:focus-visible {
    color: var(--accent-color);
    background-color: var(--hover-bg-color);
    
    & svg {
      fill: var(--accent-color);
      transform: scale(1.1);
    }
  }

  &.toggled {
    background-color: var(--hover-bg-color);

    &:hover {
      outline: none !important;
      &:active {
        background-color: var(--hover-bg-color);
      }
    }
  }
}


.toolbarSpacing {
  width: 1rem;
}


.findbar {
  position: absolute;
  top: calc(var(--toolbar-height) + 1px);
  right: 1.5rem;
  z-index: 30000;
  height: auto;
  font-size: 0.9rem;
  line-height: 1.4;
  text-align: left;
  cursor: default;
  width: 25em;
  background-color: var(--toolbar-bg-color);
  padding: 0.5rem;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.2rem;
  border: 1px solid var(--field-border-color);
  animation: fadeIn var(--transition-speed) ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

#findInput {
  width: 15em;
  padding: 0 0.6rem;
  border-radius: 6px;
  margin-bottom: 0;
  outline: none;

  &::-webkit-input-placeholder {
    color: rgba(150, 150, 155, 1);
  }
}

#findbarMessageContainer {
  min-width: 5.5em;
  display: inline-block;
  text-align: center;
}
:is(#findResultsCount, #findMsg):empty {
  display: none;
}



#sidebarContainer {
  position: absolute;
  inset-block: var(--toolbar-height) 0;
  inset-inline-start: calc(-1 * var(--sidebar-width));
  width: var(--sidebar-width);
  visibility: hidden;
  z-index: 1;
  border-top: 1px solid transparent;
  border-inline-end: 1px solid var(--toolbar-border-color);
  transition: inset-inline-start var(--transition-speed) ease;
  background-color: var(--toolbar-bg-color);
  border-right: 1px solid var(--toolbar-border-color);

  #sidebarContent {
    inset-block: 0;
    inset-inline-start: 0;
    overflow: auto;
    position: absolute;
    width: 100%;
    box-shadow: inset -1px 0 0 rgb(0 0 0 / 0.25);
  }

  #sidebarResizer {
    position: absolute;
    inset-block: 0;
    inset-inline-end: -6px;
    width: 6px;
    z-index: 200;
    cursor: ew-resize;
  }
}

#outerContainer:is(.sidebarMoving, .sidebarOpen) #sidebarContainer {
  visibility: visible;
}
#outerContainer.sidebarOpen #sidebarContainer {
  inset-inline-start: 0;
}
#outerContainer.sidebarOpen #viewerContainer {
  inset-inline-start: var(--sidebar-width);
  transition-property: inset-inline-start;
}
#outerContainer.sidebarOpen #loadingBar {
  inset-inline-start: var(--sidebar-width);
}
#outerContainer.sidebarResizing :is(#sidebarContainer, #viewerContainer, #loadingBar) {
  /* Improve responsiveness and avoid visual glitches when the sidebar is resized. */
  transition-duration: 0s;
}


.treeWithDeepNesting > .treeItem,
.treeItem > .treeItems {
  margin-inline-start: 20px;
}
.treeItem > a {
  text-decoration: none;
  display: inline-block;
  /* Subtract the right padding (left, in RTL mode) of the container: */
  min-width: calc(100% - 4px);
  height: auto;
  margin-bottom: 1px;
  padding: 2px 2px 4px;
  border-radius: 2px;
  color: var(--treeitem-color);
  font-size: 14px;
  line-height: 15px;
  user-select: none;
  white-space: normal;
  cursor: pointer;

  &:hover {
    background-color: var(--hover-bg-color);
  }
}

.treeItemToggler {
  position: relative;
  float: left;
  height: 0;
  width: 0;
  color: rgb(255 255 255 / 0.5);
  cursor: pointer;

  &::before {
    position: absolute;
    display: inline-block;
    width: 20px;
    height: 20px;

    content: "";
    background-color: light-dark(black, white);
    mask-size: cover;
    inset-inline-end: 0;

    mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z" /></svg>');
  }

  &.treeItemsHidden::before {
    mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7.41,15.41L12,10.83L16.59,15.41L18,14L12,8L6,14L7.41,15.41Z" /></svg>');
  }
  &.treeItemsHidden ~ .treeItems {
    display: none;
  }
}
